(import java.util.Calendar)
; template for scenario
; scenario for one day, 4 persons

(deftemplate scenariu
    (slot persoana)
    (slot actiune)
    (slot loc)
    (slot ora1)
    (slot min1)
    (slot sec1)
    (slot ora2)
    (slot min2)
    (slot sec2))
	
(assert (scenariu (persoana "Ana") (actiune "se trezeste") (loc "dormitor1") (ora1 00) (min1 02) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "baie1") (ora1 00) (min1 03) (sec1 30)))
(assert (scenariu (persoana "Ana") (actiune "porneste bec") (loc "baie1") (ora1 00) (min1 03) (sec1 40)))
(assert (scenariu (persoana "Ana") (actiune "spala fata") (loc "baie1") (ora1 00) (min1 03) (sec1 40) (ora2 00) (min2 04) (sec2 30)))
(assert (scenariu (persoana "Ana") (actiune "spala dinti") (loc "baie1") (ora1 00) (min1 05) (sec1 00) (ora2 00) (min2 05) (sec2 30)))
(assert (scenariu (persoana "Ana") (actiune "merge la WC") (loc "baie1") (ora1 00) (min1 06) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "spala dus") (loc "baie1") (ora1 00) (min1 10) (sec1 00) (ora2 00) (min2 20) (sec2 00)))
(assert (scenariu (persoana "Ana") (actiune "opreste bec") (loc "baie1") (ora1 00) (min1 22) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "bucatarie") (ora1 00) (min1 22) (sec1 30)))
(assert (scenariu (persoana "Ana") (actiune "porneste bec") (loc "bucatarie") (ora1 00) (min1 22) (sec1 40)))
(assert (scenariu (persoana "Ana") (actiune "mananca") (loc "bucatarie") (ora1 00) (min1 24) (sec1 00) (ora2 00) (min2 40) (sec2 00)))
(assert (scenariu (persoana "Ana") (actiune "pleaca") (ora1 01) (min1 00) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "se trezeste") (loc "dormitor1") (ora1 06) (min1 45) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "merge") (loc "baie1") (ora1 06) (min1 46) (sec1 30)))
(assert (scenariu (persoana "Ion") (actiune "porneste bec") (loc "baie1") (ora1 06) (min1 47) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "spala dinti") (loc "baie1") (ora1 06) (min1 47) (sec1 30) (ora2 06) (min2 49) (sec2 00)))
(assert (scenariu (persoana "Ion") (actiune "spala fata") (loc "baie1") (ora1 06) (min1 49) (sec1 30) (ora2 06) (min2 51) (sec2 00)))
(assert (scenariu (persoana "Ion") (actiune "opreste bec") (loc "baie1") (ora1 06) (min1 52) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "pleaca") (ora1 07) (min1 00) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "se trezeste") (loc "dormitor3") (ora1 07) (min1 20) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "merge") (loc "baie2") (ora1 07) (min1 21) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "spala dinti") (loc "baie2") (ora1 07) (min1 22) (sec1 00) (ora2 07) (min2 23) (sec2 00)))
(assert (scenariu (persoana "Vlad") (actiune "spala dus") (loc "baie2") (ora1 07) (min1 24) (sec1 00) (ora2 07) (min2 40) (sec2 00)))
(assert (scenariu (persoana "Vlad") (actiune "merge") (loc "bucatarie") (ora1 07) (min1 41) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "mananca") (loc "bucatarie") (ora1 07) (min1 42) (sec1 00) (ora2 07) (min2 50) (sec2 00)))
(assert (scenariu (persoana "Vlad") (actiune "pleaca") (ora1 08) (min1 05) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "se trezeste") (loc "dormitor2") (ora1 08) (min1 10) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "merge") (loc "baie2") (ora1 08) (min1 11) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "spala dus") (loc "baie2") (ora1 08) (min1 12) (sec1 00) (ora2 08) (min2 30) (sec2 00)))
(assert (scenariu (persoana "Alina") (actiune "merge") (loc "bucatarie") (ora1 08) (min1 31) (sec1 30)))
(assert (scenariu (persoana "Alina") (actiune "mananca") (loc "bucatarie") (ora1 08) (min1 32) (sec1 00) (ora2 08) (min2 45) (sec2 00)))
(assert (scenariu (persoana "Alina") (actiune "bea") (loc "bucatarie") (ora1 08) (min1 45) (sec1 30)))
(assert (scenariu (persoana "Alina") (actiune "pleaca") (ora1 08) (min1 55) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "vine") (ora1 10) (min1 00) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "dormitor1") (ora1 10) (min1 05) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "se culca") (loc "dormitor1") (ora1 10) (min1 10) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "se trezeste") (loc "dormitor1") (ora1 13) (min1 00) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "baie2") (ora1 13) (min1 02) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "spala fata") (loc "baie2") (ora1 13) (min1 03) (sec1 00) (ora2 13) (min2 04) (sec2 00)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "bucatarie") (ora1 13) (min1 05) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "foloseste aragaz") (loc "bucatarie") (ora1 13) (min1 30) (sec1 00) (ora2 13) (min2 25) (sec2 30)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "living") (ora1 14) (min1 04) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "foloseste televizor") (loc "living") (ora1 14) (min1 05) (sec1 30) (ora2 20) (min2 00) (sec2 30)))
(assert (scenariu (persoana "Ion") (actiune "vine") (ora1 16) (min1 10) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "merge") (loc "bucatarie") (ora1 16) (min1 15) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "mananca") (loc "bucatarie") (ora1 16) (min1 16) (sec1 00) (ora2 17) (min2 00) (sec2 00)))
(assert (scenariu (persoana "Alina") (actiune "vine") (ora1 17) (min1 00) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "merge") (loc "bucatarie") (ora1 17) (min1 02) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "merge") (loc "living") (ora1 17) (min1 02) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "aprinde televizor") (loc "living") (ora1 17) (min1 03) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "gateste") (loc "bucatarie") (ora1 17) (min1 03) (sec1 30) (ora2 18) (min2 00) (sec2 00)))
(assert (scenariu (persoana "Alina") (actiune "merge") (loc "living") (ora1 18) (min1 02) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "seteaza aer conditionat mare") (loc "living") (ora1 18) (min1 05) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "vine") (ora1 18) (min1 20) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "merge") (loc "living") (ora1 18) (min1 21) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "foloseste televizor") (loc "living") (ora1 18) (min1 23) (sec1 00) (ora2 21) (min2 00) (sec2 00)))
(assert (scenariu (persoana "Alina") (actiune "foloseste calculator") (loc "living") (ora1 18) (min1 10) (sec1 00) (ora2 21) (min2 15) (sec2 00)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "baie2") (ora1 20) (min1 01) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "spala dinti") (loc "baie2") (ora1 20) (min1 02) (sec1 00) (ora2 20) (min2 03) (sec2 30)))
(assert (scenariu (persoana "Ana") (actiune "merge") (loc "dormitor1") (ora1 20) (min1 05) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "stinge televizor") (loc "living") (ora1 20) (min1 15) (sec1 00)))
(assert (scenariu (persoana "Ana") (actiune "se culca") (loc "dormitor1") (ora1 20) (min1 15) (sec1 30)))
(assert (scenariu (persoana "Ion") (actiune "merge") (loc "baie2") (ora1 20) (min1 16) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "spala dus") (loc "baie2") (ora1 20) (min1 17) (sec1 00) (ora2 20) (min2 35) (sec2 00)))
(assert (scenariu (persoana "Ion") (actiune "merge") (loc "dormitor1") (ora1 20) (min1 37) (sec1 00)))
(assert (scenariu (persoana "Ion") (actiune "se culca") (loc "dormitor1") (ora1 20) (min1 40) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "seteaza aer conditionat mic") (loc "living") (ora1 21) (min1 02) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "merge") (loc "baie2") (ora1 21) (min1 04) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "foloseste masina de spalat") (loc "baie2") (ora1 21) (min1 05) (sec1 00) (ora2 22) (min2 30) (sec2 00)))
(assert (scenariu (persoana "Alina") (actiune "foloseste televizor") (loc "living") (ora1 21) (min1 17) (sec1 00) (ora2 23) (min2 00) (sec2 00)))
(assert (scenariu (persoana "Vlad") (actiune "merge") (loc "dormitor3") (ora1 23) (min1 00) (sec1 00)))
(assert (scenariu (persoana "Vlad") (actiune "se culca") (loc "dormitor3") (ora1 23) (min1 05) (sec1 00)))
(assert (scenariu (persoana "Alina") (actiune "merge") (loc "dormitor2") (ora1 23) (min1 05) (sec1 30)))
(assert (scenariu (persoana "Alina") (actiune "se culca") (loc "dormitor3") (ora1 23) (min1 10) (sec1 00)))


; template for senzors

(deftemplate senzor_curent (slot valoare) (slot ora) (slot min) (slot sec))
(deftemplate senzor_apa (slot valoare) (slot ora) (slot min) (slot sec))
(deftemplate senzor_temperatura (slot valoare) (slot ora) (slot min) (slot sec))

; create user function in Java for finding day of the week and season - use gregorian calendar

(defrule extract_working_day
	(prediction_day ?day)
=>
	(assert (day_of_weak ?day))
)

; prediction for hour, time interval, day of week, day of month, season

(defrule prediction_electricity
	(prediction_day ?day)
	(working_day ?day)
	(season ?day ?season)
=>
	(assert consum_working_day (average_w_day ?average))
)

(defrule adjust_prediction_average
	(prediction_day ?day)
	(average_electricity_consume ?day ?amount)
	?cwd <- (consume_w_day ?actual_prediction)
	?procent <- (eval "(/ (* 35 ?amount) 100)")
    ?scadere <- (eval "(- ?actual_prediction ?amount)")
	(test (eval "(>= ?scadere ?procent)"))	; actual_prediction >= ?amount + 35%.
=> 
	(modify ?cwd (eval "(- ?cwd ?procent)"))	;bring it closer to the average
)
